package com.csun.dsms.service.impl;

import com.csun.dsms.comment.core.support.BaseService;
import com.csun.dsms.mapper.YcDeviceDataMapper;
import com.csun.dsms.mapper.YcDeviceMapper;
import com.csun.dsms.model.domain.YcDevice;
import com.csun.dsms.model.domain.YcDeviceData;
import com.csun.dsms.model.dto.yc.YcDataDto;
import com.csun.dsms.model.dto.yc.YcDeviceQueryDto;
import com.csun.dsms.service.YcDeviceDataService;
import com.csun.dsms.service.YcDeviceService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class YcDeviceDataServiceImpl extends BaseService<YcDeviceData> implements YcDeviceDataService {

    @Resource
    private YcDeviceDataMapper ycDeviceDataMapper;

    @Resource
    private YcDeviceMapper ycDeviceMapper;


    @Override
    public List<YcDeviceData> query(YcDeviceQueryDto ycDeviceData) {
        return ycDeviceDataMapper.queryListWithPage(ycDeviceData);
    }

    @Override
    public void deleteBfDate() {
        ycDeviceDataMapper.deleteBfDate();
    }

    @Override
    public List<YcDataDto> realData(YcDeviceQueryDto dto) {
        YcDevice ycDevice = new YcDevice();
        ycDevice.setPhone(dto.getPhone());
        ycDevice.setType(dto.getType());
        ycDevice.setUser(dto.getUser());
        ycDevice.setCompany(dto.getCompany());
        List<YcDevice> devices = ycDeviceMapper.queryListWithPage(ycDevice);
        List<YcDataDto> ycDataDtoList = new ArrayList<>();
        devices.forEach(item->{
            dto.setNo(item.getNo());
            YcDeviceData ycDeviceData = ycDeviceDataMapper.queryReal(dto);
            YcDataDto ycDataDto = new YcDataDto();
            ycDataDto.setNo(item.getNo());
            ycDataDto.setId(item.getId());
            ycDataDto.setCompany(item.getCompany());
            ycDataDto.setLocation(item.getLocation());
            ycDataDto.setPhone(item.getPhone());
            ycDataDto.setUser(item.getUser());
            ycDataDto.setType(item.getType());
            ycDataDto.setPm25(ycDeviceData.getPm25());
            ycDataDto.setPm10(ycDeviceData.getPm10());
            ycDataDto.setNoise(ycDeviceData.getNoise());
            ycDataDto.setTem(ycDeviceData.getTem());
            ycDataDto.setHum(ycDeviceData.getHum());
            ycDataDto.setWp(ycDeviceData.getWp());
            ycDataDto.setWs(ycDeviceData.getWs());
            ycDataDto.setWd8(ycDeviceData.getWd8());
            ycDataDto.setWd360(ycDeviceData.getWd360());
            ycDataDto.setTsp(ycDeviceData.getTsp());
            ycDataDto.setAtm(ycDeviceData.getAtm());
            ycDataDto.setLux(ycDeviceData.getLux());
            ycDataDto.setCo(ycDeviceData.getCo());
            ycDataDto.setSo2(ycDeviceData.getSo2());
            ycDataDto.setNo2(ycDeviceData.getNo2());
            ycDataDto.setO3(ycDeviceData.getO3());
            ycDataDto.setRs(ycDeviceData.getRs());
            ycDataDto.setCreatedTime(ycDeviceData.getCreatedTime());
            ycDataDtoList.add(ycDataDto);
        });
        return ycDataDtoList;
    }
}
